package com.xwdeshj.controller;

import com.alibaba.fastjson.JSONObject;
import com.xwdeshj.service.XwCustomService;
import com.xwdeshj.utils.IMoocExceptionHandler;
import com.xwdeshj.utils.helper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by BKWJA on 2019/1/13.
 * 定制游
 */
@Slf4j
@RequestMapping("custom")
@CrossOrigin(allowCredentials = "true")
@Controller
public class XwCustomController extends IMoocExceptionHandler {

    @Autowired
    private XwCustomService xwCustomService;


    /**
     *  1、若是前台项目提交的定制申请，则判断该用户是否已经登录，登录才可以提交申请，并验证用户是否存在
     *  2、后台管理系统，根据手机号码和用户名去查找改用户是否存在
     *  @param custjson :参数值，json格式
     */
    @RequestMapping("/addcustom")
    @ResponseBody
    public JSONObject addcustom(String custjson,HttpServletRequest request){

        return xwCustomService.addcustom(custjson,request);
    }

    /**
     * 获取该用户最新的一次定制信息
     * @param user_Encryptid 用户加密id
     * @param cust_Encryptid 定制信息加密id
     * @param request
     * @return
     */
    @RequestMapping("/getcustominfo")
    @ResponseBody
    public JSONObject getcustominfo(String user_Encryptid,String cust_Encryptid,HttpServletRequest request){

        return xwCustomService.getcustominfo(user_Encryptid,cust_Encryptid,request);
    }

    /**
     * 获取定制游列表
     * @param pageindex 当前页码
     * @param pagesize 每页显示多少
     * @param starttime 开始时间
     * @param endtime 结束时间
     * @param sortfild 排序字段
     * @param sortway 排序方式
     * @param searchval 搜索值
     * @param searchkey 搜索字段
     * @param type 挑选类型
     * @param category 定制类型
     * @param datasource 数据来源
     * @param applicant 申请人
     * @param user_encryptId 定制人
     * @param request
     * @return
     */
    @RequestMapping("/getcustolist")
    @ResponseBody
    public JSONObject getcustolist(@RequestParam(value = "pageindex",defaultValue = "1")Integer pageindex,
                                   @RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize,
                                   @RequestParam(value = "starttime",defaultValue = "") String starttime,
                                   @RequestParam(value = "endtime",defaultValue = "") String endtime,
                                   @RequestParam(value = "sortfild",defaultValue = "cust_custom_time") String sortfild,
                                   @RequestParam(value = "sortway",defaultValue = "desc")String sortway,
                                   @RequestParam(value = "searchval",defaultValue = "") String searchval,
                                   @RequestParam(value = "searchkey",defaultValue = "") String searchkey,
                                   @RequestParam(value = "type",defaultValue = "")String type,
                                   @RequestParam(value = "category",defaultValue = "")String category,
                                   @RequestParam(value = "datasource",defaultValue = "")String datasource,
                                   @RequestParam(value = "applicant",defaultValue = "")String applicant,
                                   @RequestParam(value = "user_encryptId",defaultValue = "")String user_encryptId,
                                   HttpServletRequest request){

        return xwCustomService.getcustolist(pageindex,pagesize,starttime,endtime,sortfild,sortway,type,category,
                datasource,applicant,searchval,searchkey,user_encryptId,request);
    }

    /**
     * 删除
     * @param custEncryptid 定制游加密id
     * @param request
     * @return
     */
    @RequestMapping("/delcustom")
    @ResponseBody
    public JSONObject delcustom(String custEncryptid,HttpServletRequest request){

        return xwCustomService.delcustom(custEncryptid,request);
    }


    /**
     *  获取某一次的匹配店铺详细信息 ，获取某用户的所有的定制信息
     * @param pageindex
     * @param pagesize
     * @param sortfild
     * @param sortway
     * @param user_encryptId  用户加密id
     * @param cust_encryptId  定制加密id
     * @param shoptype  店铺类型
     * @param business_type  商户类型
     * @param cust_type 挑选类型 1：挑选农家，2：挑选景区
     * @param request
     * @return
     */
    @RequestMapping("/getcustomAnduserlist")
    @ResponseBody
    public JSONObject getcustomAnduserlist(@RequestParam(value = "pageindex",defaultValue = "1")Integer pageindex,
                                               @RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize,
                                               @RequestParam(value = "sortfild",defaultValue = "cust_custom_time") String sortfild,
                                               @RequestParam(value = "sortway",defaultValue = "desc")String sortway,
                                               @RequestParam(value = "user_encryptId",defaultValue = "")String user_encryptId,
                                               @RequestParam(value = "cust_encryptId",defaultValue = "")String cust_encryptId,
                                               @RequestParam(value = "shoptype",defaultValue = "")String shoptype,
                                               @RequestParam(value = "business_type",defaultValue = "")String business_type,
                                               @RequestParam(value = "cust_type",defaultValue = "")String cust_type,
                                               HttpServletRequest request){

        return xwCustomService.getcustomAnduserlist(pageindex,pagesize,sortfild,sortway,user_encryptId,cust_encryptId,
                shoptype,business_type,cust_type,request);
    }


}
